package com.lin.controller;


import com.lin.base.Result;
import com.lin.entity.Device;
import com.lin.service.impl.DeviceServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lin
 * @since 2022-06-17
 */
@RestController
@RequestMapping("/api/device")
public class DeviceController {
    @Resource
    DeviceServiceImpl deviceService;

    @GetMapping("/list")
    public Result getDevice(@RequestParam Integer departmentDid,
                            @RequestParam(required = false) String key) {
        return Result.ok(deviceService.getDeviceList(departmentDid, key));
    }

    @GetMapping("/listInfo")
    public Result getDeviceInfo(@RequestParam Integer departmentDid) {
        return Result.ok(deviceService.getDeviceInfo(departmentDid));
    }

    @PostMapping("/add")
    public Result addDevicet(@RequestBody Device device) {
        return Result.ok(deviceService.addDevice(device));
    }

    @PostMapping("/update")
    public Result updateDevice(@RequestBody Device device) {
        return Result.ok(deviceService.updateDevice(device));
    }

    @PostMapping("/remove")
    public Result removeDevice(@RequestParam Integer id) {
        return Result.ok(deviceService.removeDevice(id));
    }
}
